commit=$(shell git rev-parse --short HEAD)

md-files += "guide/head.md"
md-files += "guide/concepts.md"
md-files += "guide/build.md"
md-files += "guide/notes.md"

md-files += "man/head.md"

md-files += "man/base/head.md"
md-files += "man/base/data-types.md"
md-files += "man/base/string.md"
md-files += "man/base/printk.md"
md-files += "man/base/module.md"
md-files += "man/base/io.md"
md-files += "man/base/atomic.md"
md-files += "man/base/bitmap.md"
md-files += "man/base/notifier.md"
md-files += "man/base/cpuhp.md"
md-files += "man/base/smc.md"
md-files += "man/base/static_key.md"
md-files += "man/base/refcount.md"
md-files += "man/base/plist.md"

md-files += "man/base/lock/rtmutex.md"
md-files += "man/base/lock/percpu.md"
md-files += "man/base/lock/spinlock.md"
md-files += "man/base/lock/mutex.md"
md-files += "man/base/lock/sem.md"
md-files += "man/base/lock/rcu.md"

md-files += "man/time/head.md"
md-files += "man/time/time.md"
md-files += "man/time/hrtimer.md"
md-files += "man/time/timer.md"
md-files += "man/time/ktime.md"
md-files += "man/time/timekeeping.md"
md-files += "man/time/jiffies.md"
md-files += "man/time/delay.md"
md-files += "man/time/tick-sched.md"
md-files += "man/time/clock.md"

md-files += "man/sched/head.md"
md-files += "man/sched/async.md"
md-files += "man/sched/signal.md"
md-files += "man/sched/clock.md"
md-files += "man/sched/completion.md"
md-files += "man/sched/kthread.md"
md-files += "man/sched/preempt.md"
md-files += "man/sched/sched.md"
md-files += "man/sched/task.md"
md-files += "man/sched/tasklet.md"
md-files += "man/sched/wait.md"
md-files += "man/sched/workqueue.md"

md-files += "man/mm/head.md"
md-files += "man/mm/vma.md"
md-files += "man/mm/mmap.md"
md-files += "man/mm/page.md"
md-files += "man/mm/slab.md"
md-files += "man/mm/util.md"
md-files += "man/mm/cache.md"
md-files += "man/mm/vmalloc.md"
md-files += "man/mm/uaccess.md"
md-files += "man/mm/dma-mapping.md"
md-files += "man/mm/dmapool.md"
md-files += "man/mm/mempool.md"
md-files += "man/mm/genalloc.md"
md-files += "man/mm/gfp_mask.md"
md-files += "man/mm/set_memory.md"

md-files += "man/fs/head.md"
md-files += "man/fs/anonfs.md"
md-files += "man/fs/sysfs.md"
md-files += "man/fs/devfs.md"
md-files += "man/fs/procfs.md"
md-files += "man/fs/seq_file.md"
md-files += "man/fs/debugfs.md"
md-files += "man/fs/tracefs.md"

md-files += "man/driver/head.md"
md-files += "man/driver/base/bus.md"
md-files += "man/driver/base/device.md"
md-files += "man/driver/base/driver.md"
md-files += "man/driver/base/binding.md"
md-files += "man/driver/base/class.md"
md-files += "man/driver/base/kobject.md"
md-files += "man/driver/base/drvres.md"
md-files += "man/driver/base/platform_device.md"
md-files += "man/driver/base/of.md"
md-files += "man/driver/base/property.md"
md-files += "man/driver/base/uevent.md"
md-files += "man/driver/base/firmware.md"

md-files += "man/driver/irq.md"
md-files += "man/driver/char.md"
md-files += "man/driver/misc.md"
md-files += "man/driver/dma.md"
md-files += "man/driver/clk.md"
md-files += "man/driver/amba.md"

md-files += "man/dfx/trace.md"

md-files += "kabi/kabi.md"

all:

images=$(patsubst %.txt, %.png, $(wildcard images/*.txt))
$(images):%.png:%.txt
	@base64 -d $< > $@

all: $(images)
	@pandoc --toc -N -V CJKmainfont="SimSun" -V geometry:margin=.8in --template=template/template.tex \
		-f gfm -t latex --pdf-engine=xelatex -o ldk-${commit}.pdf ${md-files}

example:
	@pandoc --toc -N -f gfm -t latex --pdf-engine=xelatex -o gfm.pdf template/gfm.md
clean:
	@rm -f *.pdf images/*.png

.PHONY: all images
